let shallowClone = (origin) => {
    return Object.assign({},origin)
}


// 缺点：拷贝对象包含 正则表达式，函数，或者undefined等值会失败
let deepClone = (origin) => {
    let copy = origin instanceof Array ? [] : {}
    for(let key in origin){
        if (origin.hasOwnProperty(key)) {
            copy[key] = typeof origin[key] === 'object' ? deepClone(origin[key]) : origin[key]
        }
    }
    return copy
}


let obj={
    id:1,
    name:'Tom',
    msg:{
        age:18
    },
    sayHi: function () {
        console.log("hi")
    }
}
let o={}

// o = shallowClone(obj)
// o.msg.age = 2;
// obj : { id: 1, name: 'Tom', msg: { age: 2 } }
// o: { id: 1, name: 'Tom', msg: { age: 2 } }

o = deepClone(obj)
o.msg.age = 2;
// { id: 1, name: 'Tom', msg: { age: 18 } }
// { id: 1, name: 'Tom', msg: { age: 2 } }

console.log(obj)
console.log(typeof o.sayHi())
